<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>第一节课</title>
		<style type="text/css">
			/*去除原来样式*/
			
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				/*
				 * 将边框设置在中间
				 */
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 500px;
				height: 500px;
				border: 1px solid #333333;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<canvas id="canvas" width="600" height="600"></canvas>
		</div>
	</body>

	<script>
		
		window.onload = function() {
			//let oCanvas = document.getElementById('canvas');
			let oCanvas = document.getElementById("canvas");
			let pen = oCanvas.getContext("2d");

			console.dir(pen);
			
			
			//画圆参数（圆心x、y坐标，半径，起始角，结束角，顺逆时针true为逆时针，false为顺时针）
//			pen.beginPath();
//			pen.arc(300,300,100,270*Math.PI/180,true);
//			pen.closePath();
			
			
			/*pen.beginPath();
			pen.arc(80,80,50,0,180*Math.PI/180,true);
			pen.closePath();
			
			pen.strokeStyle="hotpink";
			pen.stroke();
			
			pen.beginPath();
			pen.arc(120,80,50,0,360*Math.PI/180,true);
			pen.closePath();
			pen.strokeStyle="hotpink";
			pen.stroke();*/
//			pen.beginPath();
//			pen.arc(300,100,50,0,180*Math.PI,true);
//			pen.stroke();
//			pen.closePath();
//			//pen.moveTo(300,200);
//			pen.beginPath();
//			pen.arc(300,250,100,0,180*Math.PI/180,true);
//			pen.closePath();
//			pen.stroke();

//			pen.moveTo(130,100);
//			pen.lineTo(370,100);
//			
//			pen.arcTo(400,100,400,130,30);
//			pen.lineTo(400,370)
//			pen.arcTo(400,400,370,400,30);
//			pen.lineTo(130,400);
//			pen.arcTo(100,400,100,370,30);
//			pen.lineTo(100,130);
//			pen.arcTo(100,100,130,100,30);
//			pen.stroke();


			//用arcTo()画弧度参数(控制点坐标，结束点坐标)
			
			pen.arcTo(400,400,370,400,30);
			


			//画圆角矩形
			createRound(pen,100,200,300,300,10);
			
			function createRound(pen,x,y,width,height,r){
				pen.moveTo(x+r,y);
				pen.lineTo(x+width-r,y);
				pen.arcTo(x+width,y,x+width,y+r,r);
				pen.lineTo(x+width,y+height-r);
				pen.arcTo(x+width,y+height,x+width-r,y+height,r);
				pen.lineTo(x+r,y+height);
				pen.arcTo(x,y+height,x,y+height-r,r);
				pen.lineTo(x,y+r);
				pen.arcTo(x,y,x+r,y,r);
				pen.stroke();
			}
			
			
			
		}
	</script>

</html>